/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "predicate")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Predicate.findAll", query = "SELECT p FROM Predicate p"),
    @NamedQuery(name = "Predicate.findById", query = "SELECT p FROM Predicate p WHERE p.id = :id")})
public class Predicate implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID")
    private String id;
    @ManyToMany(mappedBy = "predicateCollection")
    private Collection<GpiKpi> gpiKpiCollection;
    @JoinTable(name = "predicate_rule", joinColumns = {
        @JoinColumn(name = "Id_Predicate", referencedColumnName = "ID")}, inverseJoinColumns = {
        @JoinColumn(name = "Id_Rule", referencedColumnName = "ID")})
    @ManyToMany
    private Collection<Rule> ruleCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idPredicateViolated")
    private Collection<ExecutedRules> executedRulesCollection;

    public Predicate() {
    }

    public Predicate(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @XmlTransient
    public Collection<GpiKpi> getGpiKpiCollection() {
        return gpiKpiCollection;
    }

    public void setGpiKpiCollection(Collection<GpiKpi> gpiKpiCollection) {
        this.gpiKpiCollection = gpiKpiCollection;
    }

    @XmlTransient
    public Collection<Rule> getRuleCollection() {
        return ruleCollection;
    }

    public void setRuleCollection(Collection<Rule> ruleCollection) {
        this.ruleCollection = ruleCollection;
    }

    @XmlTransient
    public Collection<ExecutedRules> getExecutedRulesCollection() {
        return executedRulesCollection;
    }

    public void setExecutedRulesCollection(Collection<ExecutedRules> executedRulesCollection) {
        this.executedRulesCollection = executedRulesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Predicate)) {
            return false;
        }
        Predicate other = (Predicate) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.Predicate[ id=" + id + " ]";
    }
    
}
